<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title>dockerComdand  &middot; sitename</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">


<meta name="description" content="docker description" />

<meta name="keywords" content="three, four, ">


<meta property="og:title" content="dockerComdand  &middot; sitename ">
<meta property="og:site_name" content="sitename"/>
<meta property="og:url" content="https://lvzongcheng.gitee.io/tools/dockercomdand/" />
<meta property="og:locale" content="en-EN">


<meta property="og:type" content="article" />
<meta property="og:description" content="docker description"/>
<meta property="og:article:published_time" content="2017-12-14T00:00:00Z" />
<meta property="og:article:modified_time" content="2017-12-14T00:00:00Z" />

  
    
<meta property="og:article:tag" content="three">
    
<meta property="og:article:tag" content="four">
    
  

  

<script type="application/ld+json">
  {
    "@context": "http://schema.org",
    "@type": "Article",
    "headline": "dockerComdand",
    "author": {
      "@type": "Person",
      "name": "LvZongCheng"
    },
    "datePublished": "2017-12-14",
    "description": "docker description",
    "wordCount":  366 
  }
</script>



<link rel="canonical" href="https://lvzongcheng.gitee.io/tools/dockercomdand/" />

<link rel="apple-touch-icon-precomposed" sizes="144x144" href="https://lvzongcheng.gitee.io/touch-icon-144-precomposed.png">
<link href="https://lvzongcheng.gitee.io/favicon.png" rel="icon">

<meta name="generator" content="Hugo 0.60.0" />

  <!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

<link href='https://fonts.googleapis.com/css?family=Merriweather:300%7CRaleway%7COpen+Sans' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="/css/font-awesome.min.css">
<link rel="stylesheet" href="/css/style.css">
<link rel="stylesheet" href="/css/highlight/default.css">

  
  
	<script>
	  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
	  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
	  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
	  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

	  ga('create', 'Your Google Analytics tracking code', 'auto');
	  ga('send', 'pageview');

	</script>

</head>
<body>
  <main id="main-wrapper" class="container main_wrapper has-sidebar">
    <header id="main-header" class="container main_header">
  <div class="container brand">
  <div class="container title h1-like">
  <a class="baselink" href="https://lvzongcheng.gitee.io">
  LvZongCheng

</a>

</div>

  
<div class="container topline">
  
  淡定 执著 进取 自律


</div>


</div>

  <nav class="container nav primary no-print">
  

<a class="homelink" href="https://lvzongcheng.gitee.io">home</a>


  
<a href="https://lvzongcheng.gitee.io/framework" title="Show list of Frameworks">Frameworks</a>

<a href="https://lvzongcheng.gitee.io/java" title="Show list of Java">Java</a>

<a href="https://lvzongcheng.gitee.io/linux" title="Show list of Linux">Linux</a>

<a href="https://lvzongcheng.gitee.io/redis" title="Show list of Redis">Redis</a>

<a href="https://lvzongcheng.gitee.io/sql" title="Show list of SQL">SQL</a>

<a href="https://lvzongcheng.gitee.io/Spring" title="Show list of Spring">Spring</a>

<a href="https://lvzongcheng.gitee.io/tools" title="Show list of Tools">Tools</a>

<a href="https://lvzongcheng.gitee.io/webpage" title="Show list of WebPage">WebPage</a>

<a href="https://lvzongcheng.gitee.io/information" title="Show list of information">information</a>

<a href="https://lvzongcheng.gitee.io/network" title="Show list of network">network</a>

<a href="https://lvzongcheng.gitee.io/%E5%BE%AE%E6%9C%8D%E5%8A%A1" title="Show list of 微服务">微服务</a>

<a href="https://lvzongcheng.gitee.io/%E6%80%BB%E7%BB%93" title="Show list of 总结">总结</a>

<a href="https://lvzongcheng.gitee.io/%E6%9C%BA%E5%99%A8%E8%87%AA%E5%8A%A8%E5%8C%96" title="Show list of 机器自动化">机器自动化</a>

<a href="https://lvzongcheng.gitee.io/%E6%B1%87%E7%BC%96" title="Show list of 汇编">汇编</a>

<a href="https://lvzongcheng.gitee.io/%E8%AE%B0%E4%BA%8B%E6%9C%AC" title="Show list of 记事本">记事本</a>


</nav>

<div class="container nav secondary no-print">
  
<a id="contact-link-email" class="contact_link" rel="me" aria-label="Email" href="mailto:Lyc19880405@163.com">
  <span class="fa fa-envelope-square"></span></a>



<a id="contact-link-github" class="contact_link" rel="me" aria-label="Github" href="https://github.com/enten/hugo-boilerplate">
  <span class="fa fa-github-square"></span></a>




 


















</div>


  

</header>


<article id="main-content" class="container main_content single">
  <header class="container hat">
  <h1>dockerComdand
</h1>

</header>

  <div class="container content">
  <p>+++
title = &ldquo;docker 基础命令&rdquo;
date = &ldquo;2016-12-27&rdquo;
categories = [ &ldquo;docker&rdquo;]
tags = [
&ldquo;docker&rdquo;
]
+++</p>
<p>include::content/post/base.adoc[]
:toc-title: docker-base</p>
<p>=== 阿里云加速</p>
<h2 id="quote">[quote]</h2>
<h2 id="https7xefeiremirroraliyuncscom"><a href="https://7xefeire.mirror.aliyuncs.com">https://7xefeire.mirror.aliyuncs.com</a></h2>
<p>=== Dockerfile 参考
<a href="https://docs.docker.com/engine/reference/builder/">https://docs.docker.com/engine/reference/builder/</a>[]</p>
<p>=== 使用</p>
<h2 id="source">==== 获取容器 ip
[source,]</h2>
<p>docker inspect &ndash;format=&rsquo;{{.NetworkSettings.IPAddress}} {{.Config.Hostname}}&rsquo; $CONTAINER_ID</p>
<h2 class="Config Hostname" id="docker-ps-formatidxargs-i-id-docker-inspect-formatnetworksettingsipaddress-">docker ps &ndash;format=&rsquo;{{.ID}}&lsquo;|xargs -I id docker inspect &ndash;format=&rsquo;{{.NetworkSettings.IPAddress}} {</h2>
<p>==== list 镜像</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">docker images --format <span style="color:#e6db74">&#34;{{.ID}}: {{.Repository}}:{{.Tag}}&#34;</span>
</code></pre></div><p>==== list 容器</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">docker ps --format <span style="color:#e6db74">&#34;{{.ID}}: {{.Names}}&#34;</span>
</code></pre></div><p>==== 启动 <code>docker</code></p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">docker run -t -i ubuntu:14.04 /bin/bash
</code></pre></div><p>=== 操作 <code>Docker</code></p>
<p>==== <code>build</code></p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">docker build -t csphere/centos:7.1 .
</code></pre></div><p>==== <code>run</code></p>
<pre><code>-it 前台,交互模式
</code></pre><p>==== <code>log</code></p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">docker logs -f &lt;ID&gt;
</code></pre></div><p>==== 删除镜像</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">docker rmi <span style="color:#f92672">[</span>-f<span style="color:#f92672">]</span> &lt;ID&gt;
</code></pre></div><p>==== 批量删除镜像</p>
<pre><code>docker images | awk '{if($1 ~ &quot;^zookeeper&quot;&amp;&amp;$2 != &quot;1.4&quot; ){print $1&quot;:&quot;$2}}' | xargs docker rmi
</code></pre><pre><code>docker images --format &quot;{{.ID}} {{.Repository}}:{{.Tag}}&quot; | awk '{if($0 ~ &quot;&lt;none&gt;&quot; &amp;&amp; NR != 1){print $1}}' | xargs docker rmi
</code></pre><p>==== 删除容器</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"><span style="color:#f92672">=</span>删除所有容器
docker rm <span style="color:#66d9ef">$(</span>docker ps -a -q<span style="color:#66d9ef">)</span>
</code></pre></div><p>==== 关闭所有容器</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">docker stop <span style="color:#66d9ef">$(</span>docker ps -a -q<span style="color:#66d9ef">)</span>
</code></pre></div><p>==== 进入一个容器的交互模式</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">docker exec -it &lt;CONTAINER Name&gt; /bin/bash
</code></pre></div><p>==== 挂载目录</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">docker run -it -v /src/webapp:/opt/webapp ubuntu:14.04 /bin/bash
</code></pre></div><p>==== 载入镜像</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">docker load &lt; ubuntu_14.04.tar
</code></pre></div><p>==== 查看 <code>docker</code> 网络</p>
<pre><code>docker network ls
</code></pre><p>==== 容器生成镜像</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">docker commit 614122c0aabb aoct/apache2
</code></pre></div><p>==== 从主机到容器</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">sudo docker cp ./default.conf nginx:/etc/nginx/conf.d/suffusedDomain.conf
</code></pre></div><p>==== 从容器到主机</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">sudo docker cp centos7:/tmp/docker-compose-Linux-x86_64 ./docker-compose-Linux-x86_64
</code></pre></div><p>==== 删除不是 <code>dishui.io</code> 开头的镜像</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">docker images | awk <span style="color:#e6db74">&#39;{if($1 ~ &#34;&lt;none&gt;&#34; &amp;&amp; NR != 1){print $3}}&#39;</span> | xargs docker rmi
</code></pre></div><p>=== 修改 <code>Docker</code> 镜像的存储位置</p>
<p>==== 备份fstab文件</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">cp /etc/fstab /etc/fstab.<span style="color:#66d9ef">$(</span>date +%Y-%m-%d<span style="color:#66d9ef">)</span>
</code></pre></div><p>==== 停止 <code>docker</code> ， 用 <code>rsync</code> 同步 <code>/var/lib/docker</code> 到新位置 如果 <code>rsync</code> 没有安装</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">yum -y install rsync
</code></pre></div><p>==== 停止 <code>docker</code></p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">service docker stop
</code></pre></div><p>==== 同步数据</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"><span style="color:#f92672">=</span>在数据分区中建立要挂载的目录
mkdir /data/docker
<span style="color:#f92672">=</span>使用rsync工具同步
rsync -aXS /var/lib/docker/.  /data/docker/
</code></pre></div><p>==== 修改 <code>fstab</code></p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"><span style="color:#f92672">=</span>vi /etc/fstab
/data/docker /var/lib/docker  none bind <span style="color:#ae81ff">0</span> 0
</code></pre></div><p>=== Mount AWS EFS, NFS or CIFS/Samba volumes in Docker</p>
<h2 id="quote1">. 下载 插件 百度网盘
+
[quote]</h2>
<h2 id="srcdockerdockervolumenetshare032linuxamd64bin">src/docker/docker-volume-netshare_0.32_linux_amd64-bin</h2>
<p>. 启动 插件
+</p>
<pre><code>sudo nohup docker-volume-netshare cifs --username dishui --password dishui --domain storage &amp;
</code></pre><p>. 启动容器
+</p>
<pre><code>docker run -i -t --volume-driver=cifs -v 192.168.137.2/hugo:/hugo centos:7 /bin/bash
</code></pre><p>. 参考
+
<a href="http://netshare.containx.io/">http://netshare.containx.io/</a>[docker-volume-netshare]</p>
<p>[qanda]
重启后 cifs 创建的volume丢失 ::
<code>docker-volume-netshare</code> 插件机制引起的 +
CoreOS 开机启动创建volume
+</p>
<pre><code>    - name: docker-volume-netshare.service
      command: start
      content: |
        [Unit]
        Description=docker-volume-netshare
        After=docker.service
        [Service]
        User=root
        ExecStart=/opt/bin/docker-volume-netshare cifs --username dishui --password dishui --domain storage
        ExecStartPost=/usr/bin/docker volume create -d cifs --name 192.168.137.2/dishui
        LimitNOFILE=40000
        TimeoutStartSec=0

        [Install]
        WantedBy=multi-user.target
</code></pre>
</div>


  
</article>
      <footer id="main-footer" class="container main_footer">
  

  <div class="container nav foot no-print">
  
<a href="https://lvzongcheng.gitee.io/license">license</a>


  <a class="toplink" href="#">back to top</a>

</div>

  <div class="container credits">
  
<div class="container footline">
  
  code with <!-- raw HTML omitted --><!-- raw HTML omitted -->


</div>


  
<div class="container copyright">
  
  (c) 2015 yourname.


</div>


</div>

</footer>

    </main>
    
<script type="text/javascript">
  (function() {
    
    
    if (window.location.hostname == "localhost")
      return;
    var dsq = document.createElement('script'); dsq.async = true; dsq.type = 'text/javascript';
    dsq.src = '//your_disqus_shortname.disqus.com/count.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  })();
</script>



<script src="/js/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>



    
  </body>
</html>

